package com.example.gokchinesefoodmapmcdev.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.gokchinesefoodmapmcdev.entity.sys.SysRole;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SysRoleDAO extends BaseMapper<SysRole> {
    /**
     * 根据用户名查询（用户名不重复的前提），查询该用户的角色集合
     */
    @Select("SELECT * FROM sys_role WHERE role_id " +
            "IN(SELECT role_id FROM sys_user_role WHERE user_id" +
            "=(SELECT user_id FROM sys_user WHERE username = #{username}))")
    List<SysRole> selectSysRolesByUsername(String username);

    /**
     * 根据请求地址的id，查询该路径所对应可访问的角色集合
     */
    @Select("SELECT * FROM sys_role WHERE role_id " +
            "IN(SELECT role_id FROM sys_role_menu WHERE menu_id = #{menuId})")
    List<SysRole> selectSysRolesByMenuId(Long menuId);


}
